var userName = mystorage.get('userName');
var loginName = mystorage.get('loginName');
//var loginUserId =mystorage.get('loginUserId');

//进入页面自动加载用户名与真实姓名
window.onload = function () {
	$("#loginName").val(loginName);
	$("#userName").val(userName);
}

//修改密码保存
$("#change-savetBtn").click(function () {
	var data = $("#ChangeForm").serialize();
	//判断两次新密码输入是否一致
	var newPassword = $("#newPassword").val();
	var confirmPassword = $("#confirmPassword").val();
	if (!isSame(newPassword, confirmPassword)) {
		alert("新密码两次输入不一致！");
		return;
	}
	if (newPassword == '' || newPassword == null) {
		alert("新密码不能为空！");
		return;
	}
	$.ajax({
		type: "PATCH",
		url: DOMAIN + '/v1/changepassword' + isLogin,
		data: data,
		success: function (result) {
			if (result.status == 200) {
				alert("保存成功");
				$("#oldPassword").val("");
				$("#newPassword").val("");
				$("#confirmPassword").val("");
			} else {
				alert(result.msg + "  保存失败！");
			}
		}
	})
})

//判断两次密码输入是否一致
function isSame(newPassword, confirmPassword) {
	if (newPassword == confirmPassword) {
		return true;
	}
	return false;
};